package org.jeecg.modules.wlhy.customerwallet.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.jeecg.common.aspect.annotation.Dict;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

/**
 * @Description: hy_customer_offline_wallet
 * @Author: jeecg-boot
 * @Date:   2021-10-20
 * @Version: V1.0
 */
@Data
@TableName("hy_customer_offline_wallet")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="hy_customer_offline_wallet对象", description="hy_customer_offline_wallet")
public class HyCustomerWallet implements Serializable {
    private static final long serialVersionUID = 1L;

	/**id*/
	@TableId(type = IdType.ASSIGN_ID)
    @ApiModelProperty(value = "id")
    private String id;
	/**货主id*/
	@Excel(name = "货主id", width = 15, dictTable = "hy_customer", dicText = "customer_name", dicCode = "id")
	@Dict(dictTable = "hy_customer", dicText = "customer_name", dicCode = "id")
    @ApiModelProperty(value = "货主id")
    private String customerId;
	/**钱包金额*/
	@Excel(name = "钱包金额", width = 15)
    @ApiModelProperty(value = "钱包金额")
    private BigDecimal amt;

    @ApiModelProperty(value = "创建人")
    private String createBy;

	/**创建日期*/
	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "创建日期")
    private Date createTime;
	/**更新人*/
    @ApiModelProperty(value = "更新人")
    private String updateBy;
	/**更新日期*/
	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "更新日期")
    private Date updateTime;
	/**删除状态(0-正常,1-已删除)*/
    @ApiModelProperty(value = "删除状态(0-正常,1-已删除)")
    @TableLogic
    private String delFlag;
	/**账户状态*/
	@Excel(name = "账户状态", width = 15, dicCode = "wallet_st")
	@Dict(dicCode = "wallet_st")
    @ApiModelProperty(value = "账户状态")
    private String st;

	//是否冻结
	public boolean izFrozen(){
	    return "2".equals(this.st);
    }

    //账户余额是否
    public boolean izEnoughAmt(BigDecimal exchangeAmt){
	    if(this.amt==null){
	        throw new JeecgBootException("金额错误");
        }
        if(this.amt.compareTo(exchangeAmt) == -1){
            //余额不足
            return false;
        }
        return true;
    }

    @TableField(exist = false)
    private BigDecimal djsAmt;
}
